<template>
  <div>
    <el-card>
      <div id="main" style="width: 650px;height:400px;"></div>
    </el-card>
  </div>
</template>

<script>
import echarts from 'echarts'

export default {
  data () {
    return {
    }
  },
  async mounted () {
    var myChart = echarts.init(document.getElementById('main'))
    var data = []
    const res1 = await this.$http.get('topic/getAllTopicByPage')
    data.push(res1.data.total)
    const res2 = await this.$http.get('goods/getAllGoodsByPage')
    data.push(res2.data.total)
    const res3 = await this.$http.get('user/getAllUserByPage')
    data.push(res3.data.total)
    const res4 = await this.$http.get('news/getAllNewsByPage')
    data.push(res4.data.total)

    var option = {
      title: {
        text: '系统数据'
      },
      tooltip: {},
      legend: {
        data: ['总数'],
        textStyle: {
          fontSize: 18
        }
      },
      xAxis: {
        data: ['贴子', '商品', '用户', '校园资讯'],
        axisLabel: {
          show: true,
          textStyle: {
            fontSize: 18
          }

        }
      },
      yAxis: {},
      series: [{
        name: '总数',
        type: 'bar',
        data: data
      }]
    }

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option)
  }

}
</script>

<style lang="less" scoped>
#main {
  margin-top: 60px;
  margin-left: 130px;
}
</style>
